#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>

// 正确声明信号处理函数
void sig_handler(int signum, siginfo_t *info, void *myact) {
    if (signum == SIGINT) {
        printf("Got a common signal SIGINT\n");
    } else {
        printf("Got a realtime signal SIGRTMIN\n");
    }
}

int main(int argc, char **argv) {
    struct sigaction act;
    sigset_t newmask, oldmask;
    int rc;

    sigemptyset(&newmask);          // 清空信号集
    sigaddset(&newmask, SIGINT);    // 添加非实时信号
    sigaddset(&newmask, SIGRTMIN);  // 添加实时信号

    // 屏蔽信号
    sigprocmask(SIG_BLOCK, &newmask, &oldmask);

    act.sa_sigaction = sig_handler;
    act.sa_flags = SA_SIGINFO;

    if (sigaction(SIGINT, &act, NULL) < 0) {
        printf("install sigalert error\n");
    }
    if (sigaction(SIGRTMIN, &act, NULL) < 0) {
        printf("install sigalert error\n");
    }

    printf("myprocess pid=%d\n", getpid());
    sleep(60);  // 进程睡眠，等待信号

    sigprocmask(SIG_SETMASK, &oldmask, NULL);  // 恢复信号屏蔽
    return 0;
}
